package com.example.demo;

import java.util.Random;

/**
 * @Description: 简易密码生成工具类
 * @author: LiuYC
 * @date: 2021年04月21日 15:53
 */
public class PswUtil {


    /**
     * 密码的长度
     */
    private static int passwordLength;
    /**
     * 生成的密码
     */
    private static StringBuffer password = new StringBuffer();

    public static String PswUtils() {
        //初始化数字英文和符号
        String num = "0123456789";
        String english = "qwertyuiopasdfghjklzxcvbnm";
        String englishBig = "QWERTYUIOPASDFGHJKLZXCVBNM";
        String symbol = "!@#$%^&*_+-{}<>.*";
        String stringSum = num + english + englishBig + symbol;
        int length = stringSum.length();
        //定义密码长度,写死8
        passwordLength = 8;
        for (int i = 0; i < passwordLength; i++) {
            Random random = new Random();
            int a = random.nextInt(length );
            char one = stringSum.charAt(a);
            password.append(one);
        }
        System.out.print(password + "  ");
        return String.valueOf(password);
    }

}

